package com.cy.rpc.consumer.controller;

import com.cy.api.IUserService;
import com.cy.pojo.User;
import com.cy.rpc.consumer.proxy.RpcClientProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

/**
 * @Author ChenYan
 * @Date 2021/8/29 23:14
 * @Description
 */
@RestController
@RequestMapping("/user")
public class UserController {

    IUserService userService;

    @Autowired
    RpcClientProxy rpcClientProxy;

    @PostConstruct
    public void init(){
        userService = (IUserService) rpcClientProxy.createProxy(IUserService.class);
    }

    @RequestMapping("/test")
    public String test(){
        return "hello world!";
    }

    @RequestMapping("/getById")
    public User getById(Integer id){
        return userService.getById(id);
    }
}
